package com.kelaite.procurement.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.kelaite.procurement.entity.TPipelinePublic;

public interface PipelinePublicRepository extends
		JpaRepository<TPipelinePublic, Long> {

	@Query(value = "select * from t_pipeline_public where pipeline_id = ?1", nativeQuery = true)
	public List<TPipelinePublic> findByPipelineId(Long pipelineId);

	@Modifying
	@Query(value = "update t_pipeline_public o set o.bidPrice =:bidPrice, o.commMark =:commMark, o.tecMark =:tecMark, o.compMark =:compMark, o.finalWin =:finalWin, o.suggestedWin =:suggestedWin, o.gmtUpdateTime =:gmtUpdateTime, o.updatedBy =:updatedBy  where o.id =:id")
	public int updatePipelinePublic(@Param("id") Long id,
			@Param("bidPrice") Long bidPrice,
			@Param("commMark") Integer commMark,
			@Param("tecMark") Integer tecMark,
			@Param("compMark") Integer compMark,
			@Param("finalWin") boolean finalWin,
			@Param("suggestedWin") boolean suggestedWin,
			@Param("gmtUpdateTime") Date gmtUpdateTime,
			@Param("updatedBy") String updatedBy);

	@Modifying
	@Query(value = "update t_pipeline_public o set o.gmtUpdateTime =:gmtUpdateTime, o.updatedBy =:updatedBy, o.isCreateContract =:isCreateContract  where o.id =:id")
	public int updatePipelinePublicContractCreated(@Param("id") Long id,
			@Param("isCreateContract") boolean isCreateContract,
			@Param("gmtUpdateTime") Date gmtUpdateTime,
			@Param("updatedBy") String updatedBy);

	@Query(value = "select * from t_pipeline_public where pipeline_id = ?1 and suggested_win = ?2 and final_win = ?3", nativeQuery = true)
	public TPipelinePublic findByPipelineIdAndWinflag(Long pipelineId,
			boolean suggestedWin, boolean finalWin);
	
	@Query(value = "select * from t_pipeline_public where  created_by =?1 order by gmt_create_time desc", nativeQuery = true)
	public List<TPipelinePublic> getPipelinePublicOrderByTime(Long createByUser);
}
